package com.java.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jingjintao
 * @date 2021/6/17 - 0:14
 **/
public class ContextServlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletContext();
        System.out.println(context);
        System.out.println("保存之前:key1:"+context.getAttribute("key1"));
        context.setAttribute("key1","val1");
        System.out.println("ContextServlet1 key1:"+context.getAttribute("key1"));
        System.out.println("ContextServlet1 key1:"+context.getAttribute("key1"));
        System.out.println("ContextServlet1 key1:"+context.getAttribute("key1"));
        System.out.println("ContextServlet1 key1:"+context.getAttribute("key1"));
    }
}
